<?
require("enroll_config.php");

$Query = "SELECT 

code,
aid,
date,
first_name,
last_name,
position,
company,
c_address,
p_address,
email,
o_phone,
m_phone,
h_phone,
status,
city,
state,
zip,
country,
pcity,
pstate,
pzip,	
pcountry FROM $table where aid='$aid'";

$r=myQuery($Query);


header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=subscription_" . date("Ymd") . ".xls");  

echo "Code\t";
echo "Acuity Evening\t";
echo "Date\t";
echo "First name\t";
echo "Last name\t";
echo "Position\t";
echo "Company\t";
echo "Company address\t";
echo "Private address\t";
echo "Email\t";
echo "Office phone\t";
echo "Mobile phone\t";
echo "Home phone\t";
echo "Status\t\n";

for ($i=0;$i<count($r);$i++){

for ($j=0; $j < 14; $j++) {
$r[$i][$j] = str_replace("\n", " ", $r[$i][$j]);
$r[$i][$j] = str_replace("\r", " ", $r[$i][$j]);
if (empty($r[$i][$j])) {
	$r[$i][$j] = "(empty)";
}
}

echo $r[$i][0] . " \t"; 
$Query = "select presented from med_aevening where id='".$r[$i][1]."'";
$r1 = myQuery($Query);

//contact the address
$r[$i][7] = ($r[$i][7] == null ? "":$r[$i][7].",").($r[$i][14] == null ? "":$r[$i][14].",").($r[$i][15] == null ? "":$r[$i][15].",").($r[$i][16] == null ? "":$r[$i][16].",").($r[$i][17] == null ? "":$r[$i][17]);
//contact the paddress
$r[$i][8] = ($r[$i][8] == null ? "":$r[$i][8].",").($r[$i][18] == null ? "":$r[$i][18].",").($r[$i][19] == null ? "":$r[$i][19].",").($r[$i][20] == null ? "":$r[$i][20].",").($r[$i][21] == null ? "":$r[$i][21]);
//remove the ',' at last
if(substr($r[$i][7],strlen($r[$i][7])-1,strlen($r[$i][7]))==',') $r[$i][7] = substr($r[$i][7],0,strlen($r[$i][7])-1);
if(substr($r[$i][8],strlen($r[$i][8])-1,strlen($r[$i][8]))==',') $r[$i][8] = substr($r[$i][8],0,strlen($r[$i][8])-1);

echo $r1[0][0] . " \t"; 
echo $r[$i][2] . " \t"; 
echo $r[$i][3] . " \t"; 
echo $r[$i][4] . " \t"; 
echo $r[$i][5] . " \t"; 
echo $r[$i][6] . " \t"; 
echo $r[$i][7] . " \t"; 
echo $r[$i][8] . " \t"; 
echo $r[$i][9] . " \t"; 
echo $r[$i][10] . " \t"; 
echo $r[$i][11] . " \t"; 
echo $r[$i][12] . " \t"; 
echo $r[$i][13] . " \t\n"; 
}
?>